package edu.fzu.crud.common;

/**
 * @author JohnCarraway
 * @create 2020-12-02 0:49
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的json数据返回格式
 */
public class Result {

    //状态码100-成功 200-失败
    private int code;
    //提示信息
    private String msg;
    //用户需要返回给服务端的信息
    private Map<String, Object> extMsg = new HashMap<>();

    public static Result success(){
        Result result = new Result();
        result.setCode(100);
        result.setMsg("处理成功");
        return result;
    }

    public static Result failure(){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("处理失败");
        return result;
    }

    //链式调用返回
    public Result add(String key, Object value){
        this.extMsg.put(key, value);
        return this;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtMsg() {
        return extMsg;
    }

    public void setExtMsg(Map<String, Object> extMsg) {
        this.extMsg = extMsg;
    }
}
